﻿using System;
using NHibernate;
using Core.Business.Domain.Entities;
using Dominio.Core.Business.Repository;
using Core.Business.Domain.Repository;
using System.Collections.Generic;
using Core.Infra.Factories;
using NHibernate.Linq;
using System.Linq;

namespace Core.Infra.Repository {
    public class ContaRepository : IContaRepository {

        private IRepository<Conta> _repository;
        private ISession _currentSession;

        public ContaRepository(ISession session) {
            _currentSession = session;
            _repository = RepositoryFactory.GetRepository<Conta>(_currentSession);
        }

        public IList<Conta> GetAllContas() {
            
            return _currentSession.Linq<Conta>().ToList();
        }

        public void Save(Conta conta) {
            _repository.Add(conta);
        }

        public Conta GetContaBy(long idConta) {
            return _repository.GetById(idConta);
        }

        public void ChangeConta(Conta conta) {
            _repository.Change(conta);
        }
    }
}
